package com.swt.gap.controller;

import com.swt.gap.common.PageResult;
import com.swt.gap.model.dto.AddEntityDictDTO;
import com.swt.gap.model.entity.EntityDict;
import com.swt.gap.model.vo.EntityDictVO;
import com.swt.gap.service.EntityDictService;
import com.swt.gap.util.UserLoginUtils;
import io.swagger.annotations.*;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;


@Api(tags = "30 要素词典")
@RestController
@RequestMapping("/entity-dict")
public class EntityDictController {

    private final EntityDictService entityDictService;

    public EntityDictController(EntityDictService entityDictService) {
        this.entityDictService = entityDictService;
    }

    @PostMapping
    @ApiOperation(notes = "添加词典", value = "添加词典")
    @ApiImplicitParam(paramType = "body", dataType = "AddEntityDictDTO", name = "record", required = true)
    @ApiResponse(code = 201, message = "添加成功")
    public ResponseEntity<Boolean> addDictEntity(@RequestBody AddEntityDictDTO record) {
        entityDictService.addDictEntity(record);
        return ResponseEntity.status(HttpStatus.CREATED).body(true);
    }

    @GetMapping
    @ApiOperation(notes = "获取词典列表", value = "获取词典列表")
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageNum", required = true),
        @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", required = true)
    })
    @ApiResponse(code = 200, message = "获取成功", response = EntityDictVO.class, responseContainer = "List")
    public ResponseEntity<PageResult<EntityDictVO>> listDictEntities(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        return ResponseEntity.ok(entityDictService.listDictEntities(pageNum, pageSize));
    }

    @DeleteMapping("/{dictId}")
    @ApiOperation(notes = "删除词典", value = "删除词典")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "dictId", required = true)
    })
    @ApiResponse(code = 200, message = "删除成功", response = Integer.class)
    public ResponseEntity<Integer> deleteDict(@PathVariable Integer dictId) {
        return ResponseEntity.ok(entityDictService.deleteDict(dictId));
    }

    @DeleteMapping
    @ApiOperation(notes = "批量删除词典", value = "批量删除词典")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "array", name = "dictIds", required = true)
    })
    @ApiResponse(code = 200, message = "删除成功", response = Integer.class)
    public ResponseEntity<Integer> batchDeleteDict(@RequestParam List<Integer> dictIds) {
        return ResponseEntity.ok(entityDictService.batchDeleteDict(dictIds));
    }

    @PutMapping("/{dictId}")
    @ApiOperation(notes = "编辑词典", value = "编辑词典")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "dictId", required = true),
            @ApiImplicitParam(paramType = "body", dataType = "EntityDict", name = "entityDict", required = true, value = "只传需要编辑的key value")
    })
    @ApiResponse(code = 200, message = "删除成功", response = Integer.class)
    public ResponseEntity<Integer> updateDict(@PathVariable Integer dictId, @RequestBody EntityDict entityDict) {
        entityDict.setDictId(dictId);
        return ResponseEntity.ok(entityDictService.updateDict(entityDict));
    }
}
